#!/usr/bin/python3
import logging
# import json
# import logging.config

class LogHandle:
    logger = None

    def __init__(self, name, path):
        #setup_logging(default_path = "logging.json")
        self.logger = logging.getLogger(name)
        self.logger.setLevel(level=logging.INFO)
        handler = logging.FileHandler(path)
        handler.setLevel(logging.INFO)
        formatter = logging.Formatter('[%(asctime)s] - [%(name)s] - %(levelname)s - %(message)s')
        handler.setFormatter(formatter)

        console = logging.StreamHandler()
        console.setLevel(logging.INFO)

        self.logger.addHandler(handler)
        self.logger.addHandler(console)

    def comlog_debug(self, message):
        if self.logger is not None:
            self.logger.debug(message)

    def comlog_info(self, message):
        if self.logger is not None:
            self.logger.info(message)

    def comlog_warn(self, message):
        if self.logger is not None:
            self.logger.warning(message)

    def comlog_error(self, message):
        if self.logger is not None:
            self.logger.error(message)

if __name__ == '__main__':
    logger = LogHandle("Testlog")
    logger.comlog_info("Start print log")
    logger.comlog_debug("Do something")
    logger.comlog_warn("Something maybe fail.")
    logger.comlog_error("Something maybe fail.")